* Apply Roth pre-trends testing
* 4/17/2025

clear all
set more off

program main
	Roth_pretrends, design(state)
	Roth_pretrends, design(sc)
end

program Roth_pretrends
	syntax, design(str)
	
	local indiv_controls = "i.sex i.race i.hispan i.edcat age i.diffphys"
	local state_snap_controls = "i.has_bbce i.has_call i.has_faceini i.has_facerec i.has_oapp i.has_no_fp"
	
	use "$for_analysis/`design'_for_regressions_actual_ssi", clear
	local omit 6
	
	if "`design'" == "sc" {
		qui reghdfe snap ib`omit'.relyr_pos `indiv_controls' ///
			[w = perwt], a(i.hhtype i.year i.statefip) vce(cl statefip)
	}
	else if "`design'" == "state" {
		qui reghdfe snap ib`omit'.relyr_pos `indiv_controls' ///
			[w = perwt], a(i.statefip i.year) vce(cl statefip)
	}
	
	matrix sigma = e(V)
	matrix beta  = e(b)
	matrix beta1 = beta[., 2..5]
	matrix beta2 = beta[., 7..12]
	matrix beta = beta1,beta2
	matrix sigma = sigma[2..12, 2..12]
	matselrc sigma sigma2, r(1 2 3 4 6 7 8 9 10 11) c(1 2 3 4 6 7 8 9 10 11)

	* test all years >= 0
	pretrends power 0.25, pre(1/4) post(5/10)
	pretrends, numpre(4) b(beta) vcov(sigma2) omit ///
		slope(0.01) xlab(#6) ylab(#8) legend(off) xtitle("Years Since CAP Adopted")
	di `r(Power)'
	graph export "$output/`design'_Roth.png", replace
end


* Execute
main
